﻿using System;
using System.ComponentModel.Composition.Hosting;
using System.Windows;
using Microsoft.Practices.Prism.MefExtensions;
using Microsoft.Practices.Prism.Modularity;

namespace Warehouse.Silverlight.Core.Shell
{
    public class Bootstrapper : MefBootstrapper
    {
        private const string MODULES_CATALOG_URI = "/Warehouse.Silverlight.Core.Shell;component/Configuration/ModuleCatalog.xaml";

        protected override DependencyObject CreateShell()
        {
            return this.Container.GetExportedValue<Views.ShellView>();
        }

        protected override void InitializeShell()
        {
            base.InitializeShell();

            Application.Current.RootVisual = (UIElement)this.Shell;
        }

        protected override void ConfigureAggregateCatalog()
        {
            base.ConfigureAggregateCatalog();

            this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(Bootstrapper).Assembly));
        }

        protected override IModuleCatalog CreateModuleCatalog()
        {
            return Microsoft.Practices.Prism.Modularity.ModuleCatalog.CreateFromXaml(
                new Uri(MODULES_CATALOG_URI, UriKind.Relative));
        }
    }
}
